package org.tobuy.dao.proxy;

import java.util.ArrayList;
import java.util.List;

import org.tobuy.dao.IDealDAO;
import org.tobuy.dao.impl.DealDAOImpl;
import org.tobuy.dbc.DatabaseConnection;
import org.tobuy.vo.*;

public class DealDAOProxy implements IDealDAO{
	private DatabaseConnection dbc= null;
	private IDealDAO dao = null; //problem?
	
	public DealDAOProxy(){
		try{
			this.dbc = new DatabaseConnection();
		}catch(Exception e){
			e.printStackTrace();
		}
		this.dao = new DealDAOImpl(dbc.getConnection());
	}
	
	
	public boolean addDeal(Deal deal) throws Exception {
		boolean flag = false;
		try{
			flag = this.dao.addDeal(deal);
		}catch(Exception e){
			throw e;
		}finally{
			this.dbc.close();
		}
		return flag;
	}
	public List<Deal> findBoughtDeal(User buyer) throws Exception {
		List<Deal> deals = new ArrayList<Deal>();
		try{
			deals = this.dao.findBoughtDeal(buyer);
		}catch(Exception e){
			throw e;
		}finally{
			this.dbc.close();
		}
		return deals;
	}
	public List<Deal> findSoldDeal(User seller) throws Exception {
		List<Deal> deals = new ArrayList<Deal>();
		try{
			deals = this.dao.findSoldDeal(seller);
		}catch(Exception e){
			throw e;
		}finally{
			this.dbc.close();
		}
		return deals;
	}

}
